      SUBROUTINE ADCAL(TIME,TSTART,ITEST)
C
      IMPLICIT REAL * 8 (A-H,O-Z)
      REAL*8 J2,J3,J4,J22,J2R2,J3R3,J4R4
C
      COMMON/CNBODY/ J2,J3,J4,J22,ZJ20,ZMU,WWO,FLAT,AEARTH
C
      COMMON/CONSTS/ PI,TWOPI,RADIAN
      COMMON/IMAIN1/ IDATE,LSAVE,INOPT,IPLOT,NUMEQS,IPLTPE,IORB,ITAP
C
C
      COMMON/IKPLER/IKPLR
      COMMON/VECTRS/ XSAT(3),XSATDT(3),AD(3)
C
C        'ADCAL' DETERMINES THE OBLATE EARTH PERTURBATIVE ACCELERATIONS
C        UPON THE LOCAL VERTICAL FRAME. THIS SUBROUTINE IS USED ONLY
C        FOR THE INTERNAL ORBIT GENERATOR
C
C
C   THIS COMMON BLOCK IS TO READ THE ORBITAL ELEMENT DIRECTLY
C   TO COMPUTE THE POSITION AND VELOCITY COMPONENTS
C   IN INERTIAL FRAME, CODED BY K.Y., DECEMBER, 1973
C
      COMMON/XKPLER/AS,E,GF,GEI,GBW,GW
C     COMMON/XKPLER/AS,E,F,EI,BW,W,BWDOT,WDOT
      DIMENSION ROD(3),VOD(3)
      DIMENSION R2(3),XS1(3),XS2(3)
      DATA DAY,SECOND,SDAY/ 3.65D2,8.64D4,3.652477D2 /
      DATA ANGROT/ 360.9856122808D0 /
C
C     DATA RD2DG/57.2957795131D0/
C
      IF(IORB.NE.0) GO TO 10
      IF(ITEST.EQ.2) GO TO 10
C
      IF(IKPLR.EQ.0) GO TO 1
C   CONVERT DEGREES TO RADIANS
      F=GF*RADIAN
      EI=GEI*RADIAN
      BW=GBW*RADIAN
      W=GW*RADIAN
C     BWDOT=BWDOT/RD2DG
C     WDOT=WDOT/RD2DG
C   MAGNITUDE OF POSITION VECTOR
      R=(AS*(1.0D0-E**2))/(1.0D0+E*DCOS(F))
C   POSITION VECTOR ROD(3) IN ARIES INERTIAL FRAME
      THA=W+F
      ROD(1)=R*(DCOS(BW)*DCOS(THA)-DSIN(BW)*DSIN(THA)*DCOS(EI))
      ROD(2)=R*(DSIN(BW)*DCOS(THA)+DCOS(BW)*DSIN(THA)*DCOS(EI))
      ROD(3)=R*DSIN(THA)*DSIN(EI)
C   QUANTITY ZMU/(ANGULAR MOMENTUN OF ORBIT)
      UPH=DSQRT(ZMU/(AS*(1.0D0-E**2)))
C   VELOCITY VECTOR VOD(3) IN ARIES INERTIAL FRAME
C   INTERMEDIATE TERMS FOR VELOCITY COMPUTATION
      STEW=DSIN(THA)+E*DSIN(W)
      CTEW=DCOS(THA)+E*DCOS(W)
      VOD(1)=UPH*(-DCOS(BW)*STEW-DSIN(BW)*DCOS(EI)*CTEW)
      VOD(2)=UPH*(-DSIN(BW)*STEW+DCOS(BW)*DCOS(EI)*CTEW)
      VOD(3)=UPH*DSIN(EI)*CTEW
C
C   INITIAL POSITION AND VELOCITY VECTOR OUTPUT
      DO 3 I=1,3
      XSAT(I)=ROD(I)
 3    XSATDT(I)=VOD(I)
C   END OF MODIFICATION
C
      IKPLR=0
C
 1    CONTINUE
      EROT=(ANGROT*DAY)/(SDAY*SECOND)
   10 RADIUS=0
C
      DO 20 I=1,3
   20 RADIUS=RADIUS + XSAT(I)*XSAT(I)
      RADIUS=DSQRT(RADIUS)
C
      SL=XSAT(3)/RADIUS
      SL2=SL*SL
      SL3=SL*SL2
      REQOR=AEARTH/RADIUS
      REQOR2=REQOR*REQOR
      REQOR3=REQOR*REQOR2
      REQOR4=REQOR*REQOR3
C
      RM2=RADIUS*RADIUS
      RM3=RADIUS*RM2
      RM4=RADIUS*RM3
      GMOR3=ZMU/RM3
C
C        'WWO' IS THE GHA OF ARIES AT THE INSTANT VERNAL EQUINOX OCCURS
C        IN THE YEAR OF SIMULATION.  USED FOR THE 2,2 TERM IN THE
C        EXPANSION OF THE EARTH'S GRAVITATIONAL MODEL
C
      ARG=2.D0*(WWO + EROT*(TIME-TSTART))*RADIAN
C
      SNWT=DSIN(ARG)
      CSWT=DCOS(ARG)
C
      C1=1.5D0*(5.D0*SL2 - 1.D0)
      C2=2.5D0*(7.D0*SL3 - 3.D0*SL)
      C3=1.875D0*(21.D0*SL2*SL2 - 14.D0*SL2 + 1.D0)
C
      J2R2=J2*REQOR2
      J3R3=J3*REQOR3
      J4R4=J4*REQOR4
C
      CK=J2R2*C1 + J3R3*C2 + J4R4*C3
      C11=3.D0*ZMU*J22*AEARTH*AEARTH/RM3/RM4
      CKGM=CK*GMOR3
C
      DO 30 I=1,3
      R2(I)=XSAT(I)*XSAT(I)
      XS1(I)=XSAT(1)*R2(I)
   30 XS2(I)=XSAT(2)*R2(I)
C
      SUM1=3.D0*XS1(1)
      SUM2=7.D0*XS1(2)
      SUM3=2.D0*XS1(3)
C
      AD(1)=CSWT*(SUM1 - SUM2 - SUM3)
C
      SUM1=2.D0*XS2(2)
      SUM2=2.D0*XS2(3)
      SUM3=8.D0*XS2(1)
C
      AD(1)=AD(1) + SNWT*(SUM1 + SUM2 - SUM3)
C
      AD(1)=AD(1)*C11 + XSAT(1)*CKGM
C
C
C
      SUM1=7.D0*XS2(1)
      SUM2=3.D0*XS2(2)
      SUM3=2.D0*XS2(3)
C
      AD(2)=CSWT*(SUM1 - SUM2 + SUM3)
C
      SUM1=2.D0*XS1(1)
      SUM2=2.D0*XS1(3)
      SUM3=8.D0*XS1(2)
C
      AD(2)=AD(2) + SNWT*(SUM1 - SUM2 - SUM3)
C
      AD(2)=AD(2)*C11 + XSAT(2)*CKGM
C
C
C
      SUM1=3.D0*J2R2*SL
      SUM2=J3R3*C1
      SUM3=J4R4*C2
C
      AD(3)=(SUM1 + SUM2 + SUM3)*ZMU/RM2
C
      SUM1=5.D0*C11*XSAT(3)
      SUM2=CSWT*(R2(1) - R2(2))
      SUM3=2.D0*SNWT*XSAT(1)*XSAT(2)
C
      AD(3)=SUM1*(SUM2 - SUM3) - AD(3)
C
      AD(3)=XSAT(3)*CKGM + AD(3)
C
C
      RETURN
      END
